#include <iostream>
#include <unordered_set>
using namespace std;

void init(unordered_set<int> &has){
	
	int nNum1=0,nNum2=1;
	has.insert(nNum1);
	has.insert(nNum2);
	while(nNum1+nNum2<=1e6){
		
		int nNum3=nNum1+nNum2;
		has.insert(nNum3);
		nNum1=nNum2;
		nNum2=nNum3;
	}
}
int main() {

	int nCnt=0;
	int nNum;
	cin>>nNum;
	unordered_set<int> has;
	init(has);
	while(true){
		
		if(has.count(nNum-nCnt) || has.count(nNum+nCnt)){
			
			break;
		}
		nCnt++;
	}
	cout<<nCnt;
	return 0;
}
